home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / System 7.0 Samples / Edition Manager / Files.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-18  |  23.2 KB  |  528 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2.  *
  3.  *  Apple Developer Technical Support
  4.  *
  5.  *  I/O handling routines
  6.  *
  7.  *  Program:    EditionSample
  8.  *  File:       Files.c -   C Source
  9.  *
  10.  *  by:         C.K. Haun <TR>
  11.  *
  12.  *  Copyright © 1990,1991 Apple Computer, Inc.
  13.  *  All rights reserved.
  14.  *
  15.  *------------------------------------------------------------------------------
  16.  * This file handles saving and loadingg the documents created by this sample.
  17.  * All the standard data load/save is taken care of in this file, while the 
  18.  * Edition Manager specific routines are in their own files (Publish.c or 
  19.  * Subscribe.c) and are called from here.
  20.  *----------------------------------------------------------------------------*/
  21.  
  22. /* File handling here */
  23. #define __FILES__
  24.  
  25. #pragma segment Files
  26. #pragma load "EdSampheaders"                                /* see the Buildheaders.c file */
  27.  
  28. #include "EdSampdefines.h"
  29. void ReadDocData(windowCHandle newWinControl, short readRefNum);
  30.  
  31. extern void HandleSectionSave(windowCHandle theWind, Boolean writeEm, Boolean dereg, FSSpec *theSpec);
  32. extern void WritePublishers(windowCHandle theWind);
  33. extern WindowPtr AddNewWindow(Boolean showIt);
  34. extern void StorePublisher(windowCHandle shortName, SectionHandle storeSection, Rect *inRect, textSectionHandle textIn,
  35.                            OSType typeIn);
  36. extern void StoreSubscriber(windowCHandle shortName, SectionHandle secHandle, Handle inRect, Handle pictIn);
  37. extern OSErr MyReadSection(SectionHandle theSection);
  38. extern short actsToIDs[];
  39. SFTypeList myList = 
  40. {
  41.     'Fred'
  42. };
  43.  
  44.  
  45.  
  46.  
  47. /*  SaveMe saves the passes window data, and all the associated sections.
  48. *       It does NOT perform a 'safe' save, it kills the old data and recreates it.
  49. *       Future versions of this sample will do a 'safe' save.
  50. */
  51. /* windowCHandle is locked on entry to this mess */
  52. void SaveMe(windowCHandle theWind, WindowPtr theWindPtr)
  53. {
  54.     Boolean myWasChanged;
  55.     register qq;
  56.     StandardFileReply saveReply;
  57.     short saveRefNum;
  58.     FSSpec saveFileSpec;
  59.     OSErr myErr;
  60.     Str255 wName;
  61.     Handle nameStr;
  62.     extern PicHandle MyMakePicture(Rect * thisRect);
  63.     long toWrite;
  64.     extern WindowPtr gCurrentWindow;
  65.     /* if the filealias handle is 0 size, then this file has not been saved yet, so we  */
  66.     /* need to call Standard File.  I'm using the new StandardGetFile call, this */
  67.     /* call is better in (at least) two ways.  First, you no longer pass a Point as */
  68.     /* a parameter, instead, the dialog is centered on the main screen for you.  Secondly, */
  69.     /* StandardGetFile returns a FSSpec record in the reply record.  This means that you */
  70.     /* can use the new FSp type calls, as well as using the FSSpec to generate an Alias */
  71.     /* easily. */
  72.     if (GetHandleSize((Handle)(*theWind)->fileAliasHandle) == 0) {
  73.         StandardPutFile("\pSave document as....", wName, &saveReply);
  74.         if (!saveReply.sfGood)
  75.             return;
  76.         saveFileSpec = saveReply.sfFile;
  77.         if (saveReply.sfReplacing)
  78.             FSpDelete(&saveFileSpec);
  79.         /* change the name of the window to this filename */
  80.         SetWTitle(theWindPtr, saveFileSpec.name);
  81.     } else {
  82.         /* Resolve the old alias that was kept with the window  */
  83.         /* in this case I don't care if the alias needed to be updated or not, this ain't */
  84.         /* a real time critical routine */
  85.         myErr = ResolveAlias(nil, ((*theWind)->fileAliasHandle), &saveFileSpec, &myWasChanged);
  86.         if (myErr) {
  87.             ShowMe("\pResolving Alias ", myErr);
  88.             return;
  89.         }
  90.         /* kill current file, ignoring errors */
  91.         FSpDelete(&saveFileSpec);
  92.     }
  93.     SetCursor(*GetCursor(watchCursor));
  94.     myErr = FSpCreate(&saveFileSpec, 'CKH6', 'Fred', 1);
  95.     if (myErr) {
  96.         ShowMe("\pCreating file ", myErr);
  97.         SetMyCursor(actsToIDs[(*theWind)->currentAction]);
  98.         return;
  99.     }
  100.     
  101.     /* replace the nil handle with the alias record please, in our window data struct */
  102.     DisposeHandle((Handle)(*theWind)->fileAliasHandle);
  103.     if (myErr = NewAlias(nil, &saveFileSpec, &((*theWind)->fileAliasHandle))) {
  104.         ShowMe("\pDuring New Alias ", myErr);
  105.         SetMyCursor(actsToIDs[(*theWind)->currentAction]);
  106.         return;
  107.     }
  108.     /* First save the drawing commands that make up this window */
  109.     
  110.     myErr = FSpOpenDF(&saveFileSpec, fsRdWrPerm, &saveRefNum);
  111.     if (myErr) {
  112.         ShowMe("\pOpening file ", myErr);
  113.         SetMyCursor(actsToIDs[(*theWind)->currentAction]);
  114.         return;
  115.     }
  116.     /* save off lines, rects, ovals.  If there is a selection currently, it's lost */
  117.     /* lines */
  118.     toWrite = sizeof(short);
  119.     myErr = FSWrite(saveRefNum, &toWrite, (Ptr)&(*theWind)->lineCount);
  120.     if (myErr) {
  121.         ShowMe("\pWriting file ", myErr);
  122.     }
  123.     if ((*theWind)->lineCount != 0) {
  124.         HLock((Handle)(*theWind)->lineList);
  125.         toWrite = GetHandleSize((Handle)(*theWind)->lineList);
  126.         FSWrite(saveRefNum, &toWrite, *((Handle)(*theWind)->lineList));
  127.         HUnlock((Handle)(*theWind)->lineList);
  128.     }
  129.     /* rectangles, count, then a copy of the handle */
  130.     toWrite = sizeof(short);
  131.     FSWrite(saveRefNum, &toWrite, (Ptr)&(*theWind)->rectCount);
  132.     if ((*theWind)->rectCount != 0) {
  133.         HLock((Handle)(*theWind)->rectList);
  134.         toWrite = GetHandleSize((*theWind)->rectList);
  135.         FSWrite(saveRefNum, &toWrite, *((*theWind)->rectList));
  136.         HUnlock((Handle)(*theWind)->rectList);
  137.     }
  138.     /* and ovals */
  139.     toWrite = sizeof(short);
  140.     FSWrite(saveRefNum, &toWrite, (Ptr)&(*theWind)->ovalCount);
  141.     if ((*theWind)->ovalCount != 0) {
  142.         HLock((Handle)(*theWind)->ovalList);
  143.         toWrite = GetHandleSize((*theWind)->ovalList);
  144.         FSWrite(saveRefNum, &toWrite, *((*theWind)->ovalList));
  145.         HUnlock((Handle)(*theWind)->ovalList);
  146.     }
  147.     /* and pictures, I'm putting them in the data fork just because, OK? */
  148.     /* Actually, I'm doing it to prevent any conflict with resource for  */
  149.     /* subscribers.  I could check for unique IDs and all that, but sometimes */
  150.     /* simplicity works well.... */
  151.     
  152.     toWrite = sizeof(short);
  153.     FSWrite(saveRefNum, &toWrite, (Ptr)&(*theWind)->numPicts);
  154.     if ((*theWind)->numPicts != 0) {
  155.         Handle * thePict;
  156.         Handle *thePictRect;
  157.         
  158.         HLock((Handle)(*theWind)->pictHandle);
  159.         HLock((Handle)(*theWind)->pictRects);
  160.         thePict = (Handle *)*(*theWind)->pictHandle;
  161.         thePictRect = (Handle *)*(*theWind)->pictRects;
  162.         for (qq = 0; qq < (*theWind)->numPicts; qq++) {
  163.             short writeSize;
  164.             toWrite = sizeof(short);
  165.             writeSize = GetHandleSize((Handle)*thePict);
  166.             FSWrite(saveRefNum, &toWrite, (Ptr)&writeSize);
  167.             toWrite = writeSize;
  168.             HLock((Handle)*thePict);
  169.             FSWrite(saveRefNum, &toWrite, (Ptr)(*(*thePict)));
  170.             HUnlock((Handle)*thePict);
  171.             /* and the rect */
  172.             toWrite = sizeof(Rect);
  173.             HLock((Handle)*thePictRect);
  174.             FSWrite(saveRefNum, &toWrite, (Ptr)(*(*thePictRect)));
  175.             HUnlock((Handle)*thePictRect);
  176.             thePictRect += 1;
  177.             thePict += 1;
  178.         }
  179.         HUnlock((Handle)(*theWind)->pictHandle);
  180.         HUnlock((Handle)(*theWind)->pictRects);
  181.     }
  182.     toWrite = sizeof(short);
  183.     if ((*theWind)->boxHandle != nil) {
  184.         CharsHandle theText;
  185.         short textLen;
  186.         /* save the text and the rectangle */
  187.         theText = TEGetText((*theWind)->boxHandle);
  188.         HLock((Handle)theText);
  189.         textLen = GetHandleSize((Handle)theText);
  190.         /* have to write it out the length of the text now */
  191.         toWrite = sizeof(short);
  192.         FSWrite(saveRefNum, &toWrite, (Ptr)&textLen);
  193.         /* and the text itself */
  194.         toWrite = textLen;
  195.         FSWrite(saveRefNum, &toWrite, (Ptr)*theText);
  196.         /* and save out the rectangle */
  197.         toWrite = sizeof(Rect);
  198.         FSWrite(saveRefNum, &toWrite, (Ptr)&(*theWind)->textBox);
  199.     } else {
  200.         short nothing = 0;
  201.         FSWrite(saveRefNum, &toWrite, (Ptr)¬hing);       /* a pointer to nothing.  Leads to the 'No Exit' sign in Sartè */
  202.     }
  203.     FSClose(saveRefNum);
  204.     /* this takes care of the data fork of the file.  Now we need to save 
  205.     *   publisher and subcriber data in the resource fork */
  206.     HCreateResFile(saveFileSpec.vRefNum, saveFileSpec.parID, saveFileSpec.name);
  207.     if (myErr = ResError()) {
  208.         ShowMe("\pCreating Rez fork", myErr);
  209.         SetMyCursor(actsToIDs[(*theWind)->currentAction]);
  210.         return;
  211.     }
  212.     saveRefNum = HOpenResFile(saveFileSpec.vRefNum, saveFileSpec.parID, saveFileSpec.name, fsRdWrPerm);
  213.     if (myErr = ResError()) {
  214.         ShowMe("\pHOpening resource fork ", myErr);
  215.         SetMyCursor(actsToIDs[(*theWind)->currentAction]);
  216.         return;
  217.     }
  218.     /* add our 'name' string to this file (see 'The Finder Interface' chapter of IM VI) */
  219.     nameStr = GetResource('STR ', 1000);
  220.     DetachResource(nameStr);
  221.     UseResFile(saveRefNum);
  222.     AddResource(nameStr, 'STR ', -16396, "");
  223.     /* HandleSectionSave saves off the 'sect' and 'alis' resources for all our */
  224.     /* publishers and subscribers */
  225.     HandleSectionSave(theWind, true, false, &saveFileSpec);
  226.     CloseResFile(saveRefNum);
  227.     FlushVol("", saveFileSpec.vRefNum);
  228.     (*theWind)->windowDirty = false;
  229.     SetMyCursor(actsToIDs[(*theWind)->currentAction]);
  230. }
  231.  
  232. /* end SaveMe */
  233.  
  234. /* OpenFile reads in our drawing commands, and all the publisher and */
  235. /* subscriber data, and registers all our sections */
  236. WindowPtr OpenFile(FSSpec *inSpec)
  237. {
  238.     long numSections;
  239.     register qq;
  240.     long counter = 0;
  241.     OSErr myErr;
  242.     WindowPtr newWindow;
  243.     windowCHandle newWinControl;
  244.     Handle textFromFile;
  245.     FSSpec readFileSpec;
  246.     long toRead;
  247.     short readRefNum;
  248.     StandardFileReply openReply;
  249.     SFTypeList myList =  {
  250.         'Fred'
  251.     };
  252.     
  253.     if (inSpec) {                                           /* if it was called by an ODOC AppleEvent then our AppleEvent handler */
  254.         /* will pass the FSSpec that the AE contained */
  255.         readFileSpec = openReply.sfFile = *inSpec;
  256.     } else {
  257.         StandardGetFile((FileFilterProcPtr)0, 1, myList, &openReply);
  258.         if (!openReply.sfGood)
  259.             return;                                         /* scat if they canceled */
  260.         readFileSpec = openReply.sfFile;
  261.     }
  262.     if ((openReply.sfType != 'Fred') && (inSpec == nil)) {
  263.         ShowMe("\pfilter not working", 0);
  264.         return;
  265.     }
  266.     SetCursor(*GetCursor(watchCursor));
  267.     newWindow = AddNewWindow(false);                        /* ask for a new window */
  268.     if (newWindow == nil) {
  269.         InitCursor();
  270.         return(nil);
  271.     }                                                       /* bail if it failed */
  272.     newWinControl = (windowCHandle)GetWRefCon(newWindow);
  273.     HLock((Handle)newWinControl);
  274.     /* window opened, set title to file name, and create an alias to store in the */
  275.     /* struct. */
  276.     SetWTitle(newWindow, readFileSpec.name);
  277.     DisposeHandle((Handle)(*newWinControl)->fileAliasHandle);        /* kill the null handle */
  278.     if (myErr = NewAlias(nil, &readFileSpec, &((*newWinControl)->fileAliasHandle))) {
  279.         ShowMe("\pDuring New Alias ", myErr);
  280.         return;
  281.     }
  282.     /* now open the data fork of the file and read in our drawing commands */
  283.     if (myErr = FSpOpenDF(&openReply.sfFile, fsRdPerm, &readRefNum)) {
  284.         ShowMe("\pOpening file ", myErr);
  285.         return;
  286.     }
  287.     ReadDocData(newWinControl, readRefNum);
  288.     readRefNum = HOpenResFile(readFileSpec.vRefNum, readFileSpec.parID, readFileSpec.name, fsRdWrPerm);
  289.     UseResFile(readRefNum);
  290.     /* now load in the sections and aliases */
  291.     /* Load each section, and store it in the appropriate area (pub or sub) */
  292.     /* Then register the sections.  */
  293.     /* ••• NOTE: As soon as you register a section, the Edition Manager may generate an */
  294.     /* event for that section.  All the subscribers may get a Section Read event, for */
  295.     /* example, and some of the publishers will probably get a section write.  */
  296.     /*  So, don't assume anything.  Don't write sections or read sections yourself, wait for */
  297.     /* the Edition Manager to generate the right events, this will insure that you are always */
  298.     /* current and NOT fighting with the EM */
  299.     /* how many sections are there? */
  300.     numSections = Count1Resources(rSectionType);
  301.     /* loop through them all */
  302.     if (numSections) {
  303.         for (counter = 0; counter < numSections; counter++) {
  304.             SectionHandle inSection;
  305.             AliasHandle inAlias;
  306.             Handle auxDataIn;
  307.             short inID;
  308.             ResType tempRT;
  309.             Str255 tempRName;
  310.             Boolean aliasUpdated;
  311.             FSSpec tempSpec;
  312.             inSection = (SectionHandle)Get1IndResource(rSectionType, counter + 1);
  313.             /* this GetResInfo call is here to give us the ResID of the section.  Since the alias */
  314.             /* for this section was stored with the same ID, we can get it easily. */
  315.             GetResInfo((Handle)inSection, &inID, &tempRT, &tempRName);
  316.             inAlias = (AliasHandle)Get1Resource(rAliasType, inID);
  317.             myErr = ResError();
  318.             if ((myErr != 0) || (inAlias == nil))
  319.                 ShowMe("\palias error", myErr);
  320.             DetachResource((Handle)inSection);
  321.             DetachResource((Handle)inAlias);
  322.             /* depending on our type depends on what else we bring in */
  323.             /* text data or picture stuff */
  324.             switch ((*inSection)->refCon & 0xf) {
  325.                 case kPictType:
  326.                     auxDataIn = Get1Resource('RECT', inID);
  327.                     DetachResource(auxDataIn);
  328.                     break;
  329.                 case kTextType:
  330.                     /* I do need */
  331.                     /* to get my textSection record back so I have my start-end offsets */
  332.                     auxDataIn = Get1Resource(rMyTextRecordType, inID);
  333.                     DetachResource(auxDataIn);
  334.                     break;
  335.                     
  336.             }
  337.             /* Put the alias in the section, since the old handle stored there means nothing now */
  338.             
  339.             (*inSection)->alias = inAlias;
  340.             /* now we have to determine if this was a pub or sub, since we have to load the */
  341.             /* publish rectangle resource if it was a publisher */
  342.             /* Now tell the Edition Manager that this section is back on line and ready to */
  343.             /* receive events */
  344.             if (myErr = RegisterSection(&readFileSpec, inSection, &aliasUpdated)) {
  345.                 ShowMe("\pRegistering Section ", myErr);
  346.                 /*    return; */
  347.                 inSection = nil;
  348.             }
  349.             if (inSection) {
  350.                 
  351.                 if ((*inSection)->kind == stPublisher) {
  352.                     
  353.                     /* get the rectangle */
  354.                     switch ((*inSection)->refCon & 0xf) {
  355.                         case kPictType:
  356.                             HLock(auxDataIn);
  357.                             StorePublisher(newWinControl, inSection, (Rect *)*auxDataIn, nil, 'PICT');  /* in Publish.c */
  358.                             DisposeHandle(auxDataIn);
  359.                             /* mark all incoming sections as having been saved once, so we don't */
  360.                             /* delete them accidentalllly when this window closes */
  361.                             (*inSection)->refCon |= kSavedOnce;
  362.                             
  363.                             break;
  364.                         case kTextType:
  365.                             /* need to get the text contained in this thing */
  366.                             textFromFile = Get1Resource(rMyTextBlock, inID);
  367.                             DetachResource(textFromFile);
  368.                             (*(textSectionHandle)auxDataIn)->theText = textFromFile;
  369.                             /* associate the section with the text section */
  370.                             (*(textSectionHandle)auxDataIn)->theSection = inSection;
  371.                             /* and store it away */
  372.                             
  373.                             StorePublisher(newWinControl, inSection, nil, (textSectionHandle)auxDataIn, 'TEXT');
  374.                             /* mark all incoming sections as having been saved once, so we don't */
  375.                             /* delete them accidentalllly when this window closes */
  376.                             (*inSection)->refCon |= kSavedOnce;
  377.                             break;
  378.                             
  379.                     }
  380.                 } else {
  381.                     Handle picIn;
  382.                     switch ((*inSection)->refCon & 0xf) {
  383.                         case kPictType:
  384.                             picIn = (Handle)GetPicture(inID);
  385.                             DetachResource((Handle)picIn);
  386.                             if (ResError())
  387.                                 ShowMe("\ppicture get", 0);
  388.                             /* need to get the picture here */
  389.                             StoreSubscriber(newWinControl, inSection, auxDataIn, picIn);        /* in Subscribe.c */
  390.                             break;
  391.                         case kTextType:
  392.                             /* need to get the text contained in this thing */
  393.                             textFromFile = Get1Resource(rMyTextBlock, inID);
  394.                             DetachResource(textFromFile);
  395.                             (*(textSectionHandle)auxDataIn)->theText = textFromFile;
  396.                             /* associate the section with the text section */
  397.                             (*(textSectionHandle)auxDataIn)->theSection = inSection;
  398.                             (*(textSectionHandle)auxDataIn)->nextSection = nil;
  399.                             /* and store it away */
  400.                             /* I'll be using the auxDataIn field for the textSectionHandle */
  401.                             StoreSubscriber(newWinControl, inSection, auxDataIn, nil);      /* in Subscribe.c */
  402.                             
  403.                             break;
  404.                     }
  405.                 }
  406.             }
  407.         }
  408.     }
  409.     CloseResFile(readRefNum);
  410.     HUnlock((Handle)newWinControl);
  411.     ShowWindow(newWindow);
  412.     ChangePlane(newWindow);
  413.     InitCursor();
  414.     return(newWindow);
  415. }
  416.  
  417. /* Reads the actual document data out of the file.  This is not in the OpenFile function */
  418. /* for secret reasons that will become apparent in a future release of this sample..... */
  419. /* the window control structure in this window ptr is locked on entry */
  420. /* I'm passing the window instaed of the window control handle because I may */
  421. /* have to create a text edit record */
  422. void ReadDocData(windowCHandle newWinControl, short readRefNum)
  423. {
  424.     long toRead;
  425.     register qq;
  426.     short aShort;
  427.     /* read in lines, rects, ovals. */
  428.     
  429.     GetEOF(readRefNum, &toRead);
  430.     if (toRead) {                                           /* Make sure that there is some data to read */
  431.         /* lines */
  432.         toRead = sizeof(short);
  433.         FSRead(readRefNum, &toRead, (Ptr)&(*newWinControl)->lineCount);
  434.         if ((*newWinControl)->lineCount != 0) {
  435.             HUnlock((Handle)(*newWinControl)->lineList);
  436.             MySetHandleSize((Handle)(*newWinControl)->lineList, ((*newWinControl)->lineCount) * sizeof(myLine));
  437.             HLock((Handle)(*newWinControl)->lineList);
  438.             toRead = ((*newWinControl)->lineCount) * sizeof(myLine);
  439.             FSRead(readRefNum, &toRead, *((Handle)(*newWinControl)->lineList));
  440.             HUnlock((Handle)(*newWinControl)->lineList);
  441.         }
  442.         
  443.         /* rectangles, count, then a copy of the handle */
  444.         toRead = sizeof(short);
  445.         FSRead(readRefNum, &toRead, (Ptr)&(*newWinControl)->rectCount);
  446.         if ((*newWinControl)->rectCount != 0) {
  447.             HUnlock((Handle)(*newWinControl)->rectList);
  448.             MySetHandleSize((Handle)(*newWinControl)->rectList, ((*newWinControl)->rectCount) * sizeof(Rect));
  449.             HLock((Handle)(*newWinControl)->rectList);
  450.             toRead = GetHandleSize((*newWinControl)->rectList);
  451.             FSRead(readRefNum, &toRead, *((*newWinControl)->rectList));
  452.             HUnlock((Handle)(*newWinControl)->rectList);
  453.         }
  454.         /* and ovals */
  455.         toRead = sizeof(short);
  456.         FSRead(readRefNum, &toRead, (Ptr)&(*newWinControl)->ovalCount);
  457.         if ((*newWinControl)->ovalCount != 0) {
  458.             HUnlock((Handle)(*newWinControl)->ovalList);
  459.             MySetHandleSize((Handle)(*newWinControl)->ovalList, ((*newWinControl)->ovalCount) * sizeof(Rect));
  460.             HLock((Handle)(*newWinControl)->ovalList);
  461.             toRead = GetHandleSize((*newWinControl)->ovalList);
  462.             FSRead(readRefNum, &toRead, *((*newWinControl)->ovalList));
  463.             HUnlock((Handle)(*newWinControl)->ovalList);
  464.         }
  465.         toRead = sizeof(short);
  466.         FSRead(readRefNum, &toRead, (Ptr)&(*newWinControl)->numPicts);
  467.         if ((*newWinControl)->numPicts != 0) {
  468.             Handle * tempPictHand;
  469.             Handle *tempPictRects;
  470.             HUnlock((*newWinControl)->pictHandle);
  471.             HUnlock((*newWinControl)->pictRects);
  472.             MySetHandleSize((*newWinControl)->pictHandle, (sizeof(Handle) * ((*newWinControl)->numPicts)));
  473.             MySetHandleSize((*newWinControl)->pictRects, (sizeof(Handle) * ((*newWinControl)->numPicts)));
  474.             HLock((*newWinControl)->pictHandle);
  475.             HLock((*newWinControl)->pictRects);
  476.             tempPictRects = (Handle *)*((*newWinControl)->pictRects);
  477.             tempPictHand = (Handle *)*((*newWinControl)->pictHandle);
  478.             /* read in picts please */
  479.             for (qq = 0; qq < (*newWinControl)->numPicts; qq++) {
  480.                 short sizeIn;
  481.                 /* read size of pict, pict, and pict rect for each */
  482.                 toRead = sizeof(short);
  483.                 FSRead(readRefNum, &toRead, (Ptr)&sizeIn);
  484.                 *tempPictHand = NewHandle(sizeIn);
  485.                 HLock(*tempPictHand);
  486.                 toRead = sizeIn;
  487.                 FSRead(readRefNum, &toRead, (Ptr)(*(*tempPictHand)));
  488.                 HUnlock(*tempPictHand);
  489.                 *tempPictRects = NewHandle(sizeof(Rect));
  490.                 
  491.                 HLock(*tempPictRects);
  492.                 toRead = sizeof(Rect);
  493.                 FSRead(readRefNum, &toRead, (Ptr)(*(*tempPictRects)));
  494.                 HUnlock(*tempPictRects);
  495.                 tempPictRects += 1;
  496.                 tempPictHand += 1;
  497.             }
  498.             HUnlock((*newWinControl)->pictHandle);
  499.             HUnlock((*newWinControl)->pictRects);
  500.             
  501.         }
  502.         /* get any text */
  503.         toRead = sizeof(short);
  504.         FSRead(readRefNum, &toRead, (Ptr)&aShort);
  505.         if (aShort) {                                       /* if this has value (numerically, not ethically) then we need to make a TERecord */
  506.             CharsHandle theText;
  507.             Rect innerRect;
  508.             theText = (CharsHandle)NewHandle(aShort);
  509.             HLock((Handle)theText);
  510.             toRead = aShort;
  511.             FSRead(readRefNum, &toRead, (Ptr)*theText);
  512.             /* read in the rect */
  513.             toRead = sizeof(Rect);
  514.             FSRead(readRefNum, &toRead, (Ptr)&(*newWinControl)->textBox);
  515.             /* and create the TEControl */
  516.             innerRect = (*newWinControl)->textBox;
  517.             InsetRect(&innerRect, 3, 3);
  518.             (*newWinControl)->boxHandle = TENew(&innerRect, &(*newWinControl)->textBox);
  519.             TESetText((Ptr)*theText, aShort, (*newWinControl)->boxHandle);
  520.             DisposeHandle((Handle)theText);
  521.         }
  522.     }
  523.     FSClose(readRefNum);
  524. }
  525.  
  526.  
  527. #undef __FILES__
  528.